package com.zx.flow.core.config;

import com.zx.flow.api.util.Util;
import com.zx.flow.core.annotation.EnableLuckFlow;
import com.zx.flow.core.engine.FlowEngine;
import com.zx.flow.core.engine.FlowEngineImpl;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 流程引擎
 */
@Slf4j
@Configuration
public class FlowEngineAutoConfiguration {

    @Bean("flowEngine")
    public FlowEngine initFlowEngine() throws Exception {
        List<EnableLuckFlow> annotations = (List<EnableLuckFlow>) Util.getAnnotationInstanceFormSpring(
                EnableLuckFlow.class);
        EnableLuckFlow enable = annotations.get(0);

        FlowEngineImpl flowEngine = new FlowEngineImpl();
        flowEngine.setStorageType(enable.storageType());
        flowEngine.init();
        return flowEngine;
    }

}
